package com.lzy.cloud.base.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.cloud.base.dto.ShopBankDto;
import com.lzy.cloud.base.entity.ShopBank;
import com.lzy.cloud.base.mapper.ShopBankMapperExt;
import com.lzy.cloud.base.service.ShopBankService;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商家开户银行
 *
 * @author lc
 * @version 2018/8/16
 */
@Service
public class ShopBankServiceImpl implements ShopBankService {
    @Autowired
    private ShopBankMapperExt shopBankMapperExt;

    @Override
    public PageInfo<ShopBankDto> selectList(Pager<ShopBankDto> pager, ShopBankDto shopBankDto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<ShopBankDto> shopBankDtos = shopBankMapperExt.selectList(shopBankDto);
        return new PageInfo<>(shopBankDtos);
    }

    @Override
    public ShopBankDto findByAccount(String account) {
        return shopBankMapperExt.findByAccount(account);
    }

    @Override
    public Long create(ShopBankDto dto) {
        ShopBank shopBank = DozerUtils.map(dto, ShopBank.class);
        return shopBankMapperExt.insertSelective(shopBank)>0?shopBank.getId():0;
    }

    @Override
    public Boolean update(ShopBankDto map) {
        ShopBank shopBank = DozerUtils.map(map, ShopBank.class);
        return shopBankMapperExt.updateByPrimaryKeySelective(shopBank)>0?true:false;
    }
}
